using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using viBook.Models;
using viBook.Helpers;
using viBook.Repositories;

namespace viBook.Controllers
{
    public class ContentTagsController : BaseController
    {
        #region Constructors and Repository vars

        private readonly IBookRepository _bookRepository;
        private readonly IContentTagRepository _contenttagRepository;
        private readonly IUserRepository _userRepository;

        public ContentTagsController(
            IContentTagRepository contenttagRepository,
            IUserRepository userRepository,
            IBookRepository bookRepository)
        {
            _contenttagRepository = contenttagRepository;
            _userRepository = userRepository;
            _bookRepository = bookRepository;
        }

        #endregion

        public ViewResult Details(int id)
        {
            ViewBag.ListMostPopularTags = _contenttagRepository.GetMostPopularTags();
            ViewBag.ListMostPopularUser = _userRepository.GetMostPopularUsers();
            ViewBag.ListMostPopularBook = _bookRepository.GetMostPopularBook();
            return View(_contenttagRepository.FindContentTag(id));
        }

        public ActionResult FetchNextBookPage(int contentTagId, int pageNumber)
        {
            List<Book> listBooks = _contenttagRepository.FetchNextBookPage(contentTagId, pageNumber).ToList();
            return Json(listBooks.ListBookToJsonResult());
        }
    }
}